home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / wrcmdd / crsh.c next >
C/C++ Source or Header  |  1995-02-28  |  2KB  |  103 lines

  1. //*********************************************************************
  2. //
  3. //  CRSH.C - Example usage of Winsock RCMD.DLL
  4. //
  5. //
  6. //  Winsock RCMD.DLL Copyright (c) 1994 Denicomp Systems
  7. //
  8. // 
  9. //  Usage:
  10. //
  11. //     CRSH host user command
  12. //
  13. //  Where:
  14. //     host - host name of the remote host
  15. //     user - user name to use at the remote host when executing the command
  16. //     command - the command to execute at the remote host
  17. //
  18. //
  19. //  This program will execute the "command" specified on the "host" specified
  20. //  as user "user".  The output will be displayed in a window.  When the
  21. //  command is complete, it will wait for you to press Return.
  22. //
  23. //  The command must be a non-interactive command; that is, it cannot require
  24. //  any keyboard input.
  25. //
  26. //  The directory containing Winsock RCMD.DLL must be in your PATH.
  27. //
  28. //
  29. //*********************************************************************
  30.  
  31. #include <windows.h>
  32.  
  33. #include <stdio.h>
  34. #include <ctype.h>
  35. #include <string.h>
  36.  
  37. #include "winio.h"
  38. #include "rcmd.h"
  39.  
  40. char rhost[16];
  41. char ruser[16];
  42. char cmd[128];
  43. char errmsg[128];
  44.  
  45. void rsh(argc,argv)
  46.     int argc;
  47.     char *argv[];
  48. {
  49.     int a, hRCmd;
  50.     char c;
  51.  
  52.     
  53.     strcpy(rhost,argv[1]);
  54.  
  55.     strcpy(ruser,argv[2]);
  56.  
  57.     cmd[0] = '\0';
  58.     for(a = 3; a < argc; a++)
  59.     {
  60.       strcat(cmd,argv[a]);
  61.       strcat(cmd," ");
  62.     }
  63.  
  64.     hRCmd = WinsockRCmd(rhost,514,ruser,ruser,cmd,errmsg,sizeof(errmsg));
  65.  
  66.     if (hRCmd < 0)
  67.       winio_warn(0,errmsg);
  68.     else
  69.     {
  70.       while(RCmdRead(hRCmd,&c,1) > 0)
  71.        (void) putchar(c);
  72.  
  73.       printf("Press Return: ");
  74.       getchar();
  75.     }
  76.  
  77.     RCmdClose(hRCmd);
  78.  
  79. }
  80.  
  81. #define argc __argc
  82. #define argv __argv
  83.  
  84. extern int __argc;
  85. extern char **__argv;
  86.  
  87. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  88. {
  89.     
  90.     winio_settitle("Winsock RCMD DLL Sample");
  91.     nCmdShow = SW_SHOWNORMAL;
  92.  
  93.     if (! winio_init(hInstance, hPrevInstance, nCmdShow, 16384))
  94.       return 1;
  95.     
  96.     rsh(argc, argv);
  97.  
  98.     winio_close();
  99.  
  100.     return TRUE;
  101. }
  102.  
  103.